package com.example.controller;

import com.example.bean.Collect;
import com.example.bean.Goods;
import com.example.bean.Result;
import com.example.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//商家收藏功能
@RestController
public class CollectController {

    @Autowired
    CollectService collectService;

    //查询商家单个商品收藏的次数
    @RequestMapping("/api/queryNumber")
    @CrossOrigin
    public void queryNumber(@RequestParam("gId") int gId) {
        int nubmer = collectService.queryNumber(gId);
        System.out.println(nubmer);
    }

    //根据用户ID查询用户收藏列表
    @PostMapping("/api/SelectGoodsByUser")
    @CrossOrigin
    public List<Goods> SelectGoodsByUser(@RequestParam("uId") int uId) {
        return collectService.SelectGoodsByUser(uId);
    }

    //点击收藏按钮收藏商品
    @RequestMapping("/api/collectById")
    @CrossOrigin
    public Result collectById(@RequestBody Collect collect) {
        return collectService.insertById(collect.getUId(), collect.getGId());
    }

    //点击收藏按钮取消收藏
    @RequestMapping("/api/deleteCollect")
    @CrossOrigin
    public Result deleteCollect(@RequestBody Collect collect) {
        return collectService.deleteCollect(collect.getUId(), collect.getGId());
    }
    //判断用户是否收藏过某商品
    @RequestMapping("/api/selectById")
    @CrossOrigin
    public Result selectById(@RequestBody Collect collect){
        return collectService.selectById(collect.getUId(),collect.getGId());
    }

}
